import java.awt.Button;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;


public class QuickSum extends JFrame{
    static int currentValue = 0;

    public static void main(String[] args) {
        //create "main" object here
        final QuickSum program = new QuickSum();
        program.setVisible(true);
        program.setLayout(new GridLayout(3,3));
        program.setSize(300,300);
        program.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        


        //adding buttons
        final Button buttonOne = new Button("1");
        final Button buttonTwo = new Button("2");
        final Button buttonThree = new Button("3");
        final Button buttonFour = new Button("4");
        final Button buttonFive = new Button("5");
        final Button buttonSix = new Button("6");
        final Button buttonSeven = new Button("7");
        final Button buttonEight = new Button("8");
        final Button buttonNine = new Button("9");

        program.add(buttonOne);
        program.add(buttonTwo);
        program.add(buttonThree);
        program.add(buttonFour);
        program.add(buttonFive);
        program.add(buttonSix);
        program.add(buttonSeven);
        program.add(buttonEight);
        program.add(buttonNine);



        //action listener
        ActionListener listenerOne = new ActionListener(){
            public void actionPerformed(ActionEvent event) {
                Object source = event.getSource();

                if (source == buttonOne){
                    currentValue += 1;
                    System.out.println(currentValue);
                }else if(source == buttonTwo){
                    currentValue += 2;
                    System.out.println(currentValue);
                }else if(source == buttonThree){
                    currentValue += 3;
                    System.out.println(currentValue);
                }else if(source == buttonFour){
                    currentValue += 4;
                    System.out.println(currentValue);
                }else if(source == buttonFive){
                    currentValue += 5;
                    System.out.println(currentValue);
                }else if(source == buttonSix){
                    currentValue += 6;
                    System.out.println(currentValue);
                }else if(source == buttonSeven){
                    currentValue += 7;
                    System.out.println(currentValue);
                }else if(source == buttonEight){
                    currentValue += 8;
                    System.out.println(currentValue);
                }else if(source == buttonNine){
                    currentValue += 9;
                    System.out.println(currentValue);
                }
                program.setTitle("Sum: " + currentValue);
                program.validateTree();
            }
        };
        


         buttonOne.addActionListener(listenerOne);
         buttonTwo.addActionListener(listenerOne);
         buttonThree.addActionListener(listenerOne);
         buttonFour.addActionListener(listenerOne);
         buttonFive.addActionListener(listenerOne);
         buttonSix.addActionListener(listenerOne);
         buttonSeven.addActionListener(listenerOne);
         buttonEight.addActionListener(listenerOne);
         buttonNine.addActionListener(listenerOne);




    }
}
